<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Exporting objects</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GIO Reference Manual">
<link rel="up" href="ch29.html" title="Migrating to GDBus">
<link rel="prev" href="ch29s05.html" title="Client-side GObject bindings">
<link rel="next" href="gio-hierarchy.html" title="Object Hierarchy">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="ch29s05.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="ch29.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GIO Reference Manual</th>
<td><a accesskey="n" href="gio-hierarchy.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="id387070"></a>Exporting objects</h2></div></div></div>
<p>
      With dbus-glib, exporting an object over D-Bus works by generating
      a bunch of glue code from your introspection XML with
      <span class="command"><strong>dbus-binding-tool</strong></span>. The glue code gets included in
      your source, and you need to call
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="function"><a href="/usr/share/gtk-doc/html/dbus-glib/dbus-glib-DBus-GObject-related-functions.html#dbus-g-object-type-install-info">dbus_g_object_type_install_info</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">TYPE_MYOBJECT</span><span class="symbol">,</span>
<span class="normal">                                 </span><span class="symbol">&amp;</span><span class="normal">dbus_glib_myobject_object_info</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      in your <code class="function">class_init()</code> function to tell dbus-glib about your type.
      To actually export an instance, you call
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="function"><a href="/usr/share/gtk-doc/html/dbus-glib/dbus-glib-DBusGConnection.html#dbus-g-connection-register-g-object">dbus_g_connection_register_g_object</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">system_bus_connection</span><span class="symbol">,</span>
<span class="normal">                                     my_object_path</span><span class="symbol">,</span>
<span class="normal">                                     </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">my_object</span><span class="symbol">));</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>

    </p>
<p>
      The GDBus way of exporting an object works by embedding the
      introspection XML in the source, creating introspection data
      structures from it with <a class="link" href="gio-D-Bus-Introspection-Data.html#g-dbus-node-info-new-for-xml" title="g_dbus_node_info_new_for_xml ()"><code class="function">g_dbus_node_info_new_for_xml()</code></a>, and
      passing that along when you register the object:
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal"> introspection_xml</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span>
<span class="normal">  </span><span class="string">"&lt;node&gt;"</span>
<span class="normal">  </span><span class="string">"  &lt;interface name='org.gtk.GDBus.TestPeerInterface'&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;method name='HelloWorld'&gt;"</span>
<span class="normal">  </span><span class="string">"      &lt;arg type='s' name='greeting' direction='in'/&gt;"</span>
<span class="normal">  </span><span class="string">"      &lt;arg type='s' name='response' direction='out'/&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;/method&gt;"</span>
<span class="normal">  </span><span class="string">"  &lt;/interface&gt;"</span>
<span class="normal">  </span><span class="string">"&lt;/node&gt;"</span><span class="symbol">;</span>

<span class="comment">/* parse introspection data */</span>
<span class="normal">introspection_data </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="gio-D-Bus-Introspection-Data.html#g-dbus-node-info-new-for-xml">g_dbus_node_info_new_for_xml</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">introspection_xml</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="symbol">/</span>
<span class="normal">id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GDBusConnection.html#g-dbus-connection-register-object">g_dbus_connection_register_object</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                                        </span><span class="string">"/org/gtk/GDBus/TestObject"</span><span class="symbol">,</span>
<span class="normal">                                        </span><span class="string">"org.gtk.GDBus.TestPeerInterface"</span><span class="symbol">,</span>
<span class="normal">                                        introspection_data</span><span class="symbol">-&gt;</span><span class="normal">interfaces</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">],</span>
<span class="normal">                                        </span><span class="symbol">&amp;</span><span class="normal">interface_vtable</span><span class="symbol">,</span>
<span class="normal">                                        <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal">  </span><span class="comment">/* user_data */</span>
<span class="normal">                                        <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal">  </span><span class="comment">/* user_data_free_func */</span>
<span class="normal">                                        <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span><span class="normal"> </span><span class="comment">/* GError** */</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    </p>
<p>
      The actual implementation of the exported object is done by specifying
      a <a class="link" href="GDBusConnection.html#GDBusInterfaceVTable" title="GDBusInterfaceVTable"><span class="type">GDBusInterfaceVTable</span></a> that has <code class="function">method_call()</code>, <code class="function">get_property()</code> and
      <code class="function">set_property()</code> methods. There is no direct support beyond that for
      exporting <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObjects</span></a>, so there is quite a bit of manual work involved,
      as you can see in the following example.
    </p>
<p>
      Since the VTable methods don't have any direct <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> support, we
      pass the exported object as <em class="parameter"><code>user_data</code></em>. Also note that we have to handle
      the emission of the PropertiesChanged signal ourselves, by connecting
      to ::notify.
    </p>
<div class="example">
<a name="gdbus-export"></a><p class="title"><b>Example 20. Exporting a GObject</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;gio/gio.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;stdlib.h&gt;</span>

<span class="comment">/* ---------------------------------------------------------------------------------------------------- */</span>

<span class="comment">/* The object we want to export */</span>
<span class="keyword">typedef</span><span class="normal"> </span><span class="keyword">struct</span><span class="normal"> </span><span class="classname">_MyObjectClass</span><span class="normal"> MyObjectClass</span><span class="symbol">;</span>
<span class="keyword">typedef</span><span class="normal"> </span><span class="keyword">struct</span><span class="normal"> </span><span class="classname">_MyObject</span><span class="normal"> MyObject</span><span class="symbol">;</span>

<span class="keyword">struct</span><span class="normal"> </span><span class="classname">_MyObjectClass</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">GObjectClass</span><span class="normal"> parent_class</span><span class="symbol">;</span>
<span class="cbracket">}</span><span class="symbol">;</span>

<span class="keyword">struct</span><span class="normal"> </span><span class="classname">_MyObject</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">GObject</span><span class="normal"> parent_instance</span><span class="symbol">;</span>

<span class="normal">  </span><span class="usertype">gint</span><span class="normal"> count</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">name</span><span class="symbol">;</span>
<span class="cbracket">}</span><span class="symbol">;</span>

<span class="keyword">enum</span>
<span class="cbracket">{</span>
<span class="normal">  PROP_0</span><span class="symbol">,</span>
<span class="normal">  PROP_COUNT</span><span class="symbol">,</span>
<span class="normal">  PROP_NAME</span>
<span class="cbracket">}</span><span class="symbol">;</span>

<span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Type-Information.html#G-DEFINE-TYPE:CAPS">G_DEFINE_TYPE</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">MyObject</span><span class="symbol">,</span><span class="normal"> my_object</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/gobject/unstable/gobject-Type-Information.html#G-TYPE-OBJECT:CAPS">G_TYPE_OBJECT</a></span><span class="symbol">);</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_object_finalize</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">object</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">MyObject</span><span class="symbol">*)</span><span class="normal">object</span><span class="symbol">;</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free">g_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">name</span><span class="symbol">);</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT-CLASS:CAPS">G_OBJECT_CLASS</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">my_object_parent_class</span><span class="symbol">)-&gt;</span><span class="function">finalize</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">object</span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_object_init</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">object</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  object</span><span class="symbol">-&gt;</span><span class="normal">count </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="normal">  object</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">=</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_object_get_property</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal">    </span><span class="symbol">*</span><span class="normal">object</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">guint</span><span class="normal">       prop_id</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">GValue</span><span class="normal">     </span><span class="symbol">*</span><span class="normal">value</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">GParamSpec</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">pspec</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">MyObject</span><span class="symbol">*)</span><span class="normal">object</span><span class="symbol">;</span>

<span class="normal">  </span><span class="keyword">switch</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">prop_id</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">case</span><span class="normal"> PROP_COUNT</span><span class="symbol">:</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-value-set-int">g_value_set_int</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">,</span><span class="normal"> myobj</span><span class="symbol">-&gt;</span><span class="normal">count</span><span class="symbol">);</span>
<span class="normal">      </span><span class="keyword">break</span><span class="symbol">;</span>

<span class="normal">    </span><span class="keyword">case</span><span class="normal"> PROP_NAME</span><span class="symbol">:</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-value-set-string">g_value_set_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">,</span><span class="normal"> myobj</span><span class="symbol">-&gt;</span><span class="normal">name</span><span class="symbol">);</span>
<span class="normal">      </span><span class="keyword">break</span><span class="symbol">;</span>

<span class="label">    default:</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT-WARN-INVALID-PROPERTY-ID:CAPS">G_OBJECT_WARN_INVALID_PROPERTY_ID</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">object</span><span class="symbol">,</span><span class="normal"> prop_id</span><span class="symbol">,</span><span class="normal"> pspec</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_object_set_property</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">object</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">guint</span><span class="normal">         prop_id</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">GValue</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">value</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">GParamSpec</span><span class="normal">   </span><span class="symbol">*</span><span class="normal">pspec</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">MyObject</span><span class="symbol">*)</span><span class="normal">object</span><span class="symbol">;</span>

<span class="normal">  </span><span class="keyword">switch</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">prop_id</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">case</span><span class="normal"> PROP_COUNT</span><span class="symbol">:</span>
<span class="normal">      myobj</span><span class="symbol">-&gt;</span><span class="normal">count </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-value-get-int">g_value_get_int</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">);</span>
<span class="normal">      </span><span class="keyword">break</span><span class="symbol">;</span>

<span class="normal">    </span><span class="keyword">case</span><span class="normal"> PROP_NAME</span><span class="symbol">:</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free">g_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">name</span><span class="symbol">);</span>
<span class="normal">      myobj</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-value-dup-string">g_value_dup_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">);</span>
<span class="normal">      </span><span class="keyword">break</span><span class="symbol">;</span>

<span class="label">    default:</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT-WARN-INVALID-PROPERTY-ID:CAPS">G_OBJECT_WARN_INVALID_PROPERTY_ID</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">object</span><span class="symbol">,</span><span class="normal"> prop_id</span><span class="symbol">,</span><span class="normal"> pspec</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_object_class_init</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">MyObjectClass</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">class</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">GObjectClass</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">gobject_class </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT-CLASS:CAPS">G_OBJECT_CLASS</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">class</span><span class="symbol">);</span>

<span class="normal">  gobject_class</span><span class="symbol">-&gt;</span><span class="normal">finalize </span><span class="symbol">=</span><span class="normal"> my_object_finalize</span><span class="symbol">;</span>
<span class="normal">  gobject_class</span><span class="symbol">-&gt;</span><span class="normal">set_property </span><span class="symbol">=</span><span class="normal"> my_object_set_property</span><span class="symbol">;</span>
<span class="normal">  gobject_class</span><span class="symbol">-&gt;</span><span class="normal">get_property </span><span class="symbol">=</span><span class="normal"> my_object_get_property</span><span class="symbol">;</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-class-install-property">g_object_class_install_property</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gobject_class</span><span class="symbol">,</span>
<span class="normal">                                   PROP_COUNT</span><span class="symbol">,</span>
<span class="normal">                                   </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-param-spec-int">g_param_spec_int</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"count"</span><span class="symbol">,</span>
<span class="normal">                                                     </span><span class="string">"Count"</span><span class="symbol">,</span>
<span class="normal">                                                     </span><span class="string">"Count"</span><span class="symbol">,</span>
<span class="normal">                                                     </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">99999</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span>
<span class="normal">                                                     <a href="http://library.gnome.org/devel/gobject/unstable/gobject-GParamSpec.html#G-PARAM-READWRITE:CAPS">G_PARAM_READWRITE</a></span><span class="symbol">));</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-class-install-property">g_object_class_install_property</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gobject_class</span><span class="symbol">,</span>
<span class="normal">                                   PROP_NAME</span><span class="symbol">,</span>
<span class="normal">                                   </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Standard-Parameter-and-Value-Types.html#g-param-spec-string">g_param_spec_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"name"</span><span class="symbol">,</span>
<span class="normal">                                                        </span><span class="string">"Name"</span><span class="symbol">,</span>
<span class="normal">                                                        </span><span class="string">"Name"</span><span class="symbol">,</span>
<span class="normal">                                                        <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span>
<span class="normal">                                                        <a href="http://library.gnome.org/devel/gobject/unstable/gobject-GParamSpec.html#G-PARAM-READWRITE:CAPS">G_PARAM_READWRITE</a></span><span class="symbol">));</span>
<span class="cbracket">}</span>

<span class="comment">/* A method that we want to export */</span>
<span class="type">void</span>
<span class="function">my_object_change_count</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj</span><span class="symbol">,</span>
<span class="normal">                        </span><span class="usertype">gint</span><span class="normal">      change</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  myobj</span><span class="symbol">-&gt;</span><span class="normal">count </span><span class="symbol">=</span><span class="normal"> </span><span class="number">2</span><span class="normal"> </span><span class="symbol">*</span><span class="normal"> myobj</span><span class="symbol">-&gt;</span><span class="normal">count </span><span class="symbol">+</span><span class="normal"> change</span><span class="symbol">;</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-notify">g_object_notify</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">),</span><span class="normal"> </span><span class="string">"count"</span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="comment">/* ---------------------------------------------------------------------------------------------------- */</span>

<span class="keyword">static</span><span class="normal"> </span><span class="usertype">GDBusNodeInfo</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">introspection_data </span><span class="symbol">=</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>

<span class="comment">/* Introspection data for the service we are exporting */</span>
<span class="keyword">static</span><span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal"> introspection_xml</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span>
<span class="normal">  </span><span class="string">"&lt;node&gt;"</span>
<span class="normal">  </span><span class="string">"  &lt;interface name='org.myorg.MyObject'&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;method name='ChangeCount'&gt;"</span>
<span class="normal">  </span><span class="string">"      &lt;arg type='i' name='change' direction='in'/&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;/method&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;property type='i' name='Count' access='read'/&gt;"</span>
<span class="normal">  </span><span class="string">"    &lt;property type='s' name='Name' access='readwrite'/&gt;"</span>
<span class="normal">  </span><span class="string">"  &lt;/interface&gt;"</span>
<span class="normal">  </span><span class="string">"&lt;/node&gt;"</span><span class="symbol">;</span>


<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">handle_method_call</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal">       </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">           </span><span class="symbol">*</span><span class="normal">sender</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">           </span><span class="symbol">*</span><span class="normal">object_path</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">           </span><span class="symbol">*</span><span class="normal">interface_name</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">           </span><span class="symbol">*</span><span class="normal">method_name</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="usertype">GVariant</span><span class="normal">              </span><span class="symbol">*</span><span class="normal">parameters</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="usertype">GDBusMethodInvocation</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">invocation</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="usertype">gpointer</span><span class="normal">               user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> user_data</span><span class="symbol">;</span>

<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">method_name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"ChangeCount"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">      </span><span class="usertype">gint</span><span class="normal"> change</span><span class="symbol">;</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-get">g_variant_get</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">parameters</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"(i)"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">change</span><span class="symbol">);</span>

<span class="normal">      </span><span class="function">my_object_change_count</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">,</span><span class="normal"> change</span><span class="symbol">);</span>

<span class="normal">      </span><span class="function"><a href="GDBusMethodInvocation.html#g-dbus-method-invocation-return-value">g_dbus_method_invocation_return_value</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">invocation</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#GVariant">GVariant</a> </span><span class="symbol">*</span>
<span class="function">handle_get_property</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal">  </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">sender</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">object_path</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">interface_name</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">property_name</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="usertype">GError</span><span class="normal">          </span><span class="symbol">**</span><span class="normal">error</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="usertype">gpointer</span><span class="normal">          user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">GVariant</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">ret</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> user_data</span><span class="symbol">;</span>

<span class="normal">  ret </span><span class="symbol">=</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">property_name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Count"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">      ret </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-new-int32">g_variant_new_int32</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">count</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="normal">  </span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">property_name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Name"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">      ret </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-new-string">g_variant_new_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">?</span><span class="normal"> myobj</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">:</span><span class="normal"> </span><span class="string">""</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">  </span><span class="keyword">return</span><span class="normal"> ret</span><span class="symbol">;</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">handle_set_property</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal">  </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">sender</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">object_path</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">interface_name</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">property_name</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="usertype">GVariant</span><span class="normal">         </span><span class="symbol">*</span><span class="normal">value</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="usertype">GError</span><span class="normal">          </span><span class="symbol">**</span><span class="normal">error</span><span class="symbol">,</span>
<span class="normal">                     </span><span class="usertype">gpointer</span><span class="normal">          user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> user_data</span><span class="symbol">;</span>

<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">property_name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Count"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-set">g_object_set</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"count"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-get-int32">g_variant_get_int32</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">),</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="normal">  </span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">property_name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Name"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="cbracket">{</span>
<span class="normal">      </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-set">g_object_set</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"name"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-get-string">g_variant_get_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">),</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">  </span><span class="keyword">return</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span>


<span class="comment">/* for now */</span>
<span class="keyword">static</span><span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">GDBusInterfaceVTable</span><span class="normal"> interface_vtable </span><span class="symbol">=</span>
<span class="cbracket">{</span>
<span class="normal">  handle_method_call</span><span class="symbol">,</span>
<span class="normal">  handle_get_property</span><span class="symbol">,</span>
<span class="normal">  handle_set_property</span>
<span class="cbracket">}</span><span class="symbol">;</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">send_property_change</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal">         </span><span class="symbol">*</span><span class="normal">obj</span><span class="symbol">,</span>
<span class="normal">                      </span><span class="usertype">GParamSpec</span><span class="normal">      </span><span class="symbol">*</span><span class="normal">pspec</span><span class="symbol">,</span>
<span class="normal">                      </span><span class="usertype">GDBusConnection</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">GVariantBuilder</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">builder</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">GVariantBuilder</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">invalidated_builder</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">MyObject </span><span class="symbol">*)</span><span class="normal">obj</span><span class="symbol">;</span>

<span class="normal">  builder </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-builder-new">g_variant_builder_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariantType.html#G-VARIANT-TYPE-ARRAY:CAPS">G_VARIANT_TYPE_ARRAY</a></span><span class="symbol">);</span>
<span class="normal">  invalidated_builder </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-builder-new">g_variant_builder_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariantType.html#G-VARIANT-TYPE:CAPS">G_VARIANT_TYPE</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"as"</span><span class="symbol">));</span>

<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">pspec</span><span class="symbol">-&gt;</span><span class="normal">name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"count"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">builder</span><span class="symbol">,</span>
<span class="normal">                           </span><span class="string">"{sv}"</span><span class="symbol">,</span>
<span class="normal">                           </span><span class="string">"Count"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-new-int32">g_variant_new_int32</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">count</span><span class="symbol">));</span>
<span class="normal">  </span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">pspec</span><span class="symbol">-&gt;</span><span class="normal">name</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"name"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">    </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">builder</span><span class="symbol">,</span>
<span class="normal">                           </span><span class="string">"{sv}"</span><span class="symbol">,</span>
<span class="normal">                           </span><span class="string">"Name"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-new-string">g_variant_new_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">?</span><span class="normal"> myobj</span><span class="symbol">-&gt;</span><span class="normal">name </span><span class="symbol">:</span><span class="normal"> </span><span class="string">""</span><span class="symbol">));</span>

<span class="normal">  </span><span class="function"><a href="GDBusConnection.html#g-dbus-connection-emit-signal">g_dbus_connection_emit_signal</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                                 <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span>
<span class="normal">                                 </span><span class="string">"/org/myorg/MyObject"</span><span class="symbol">,</span>
<span class="normal">                                 </span><span class="string">"org.freedesktop.DBus.Properties"</span><span class="symbol">,</span>
<span class="normal">                                 </span><span class="string">"PropertiesChanged"</span><span class="symbol">,</span>
<span class="normal">                                 </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-new">g_variant_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"(sa{sv}as)"</span><span class="symbol">,</span>
<span class="normal">                                                </span><span class="string">"org.myorg.MyObject"</span><span class="symbol">,</span>
<span class="normal">                                                builder</span><span class="symbol">,</span>
<span class="normal">                                                invalidated_builder</span><span class="symbol">),</span>
<span class="normal">                                 <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">on_bus_acquired</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                 </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">     </span><span class="symbol">*</span><span class="normal">name</span><span class="symbol">,</span>
<span class="normal">                 </span><span class="usertype">gpointer</span><span class="normal">         user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj </span><span class="symbol">=</span><span class="normal"> user_data</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">guint</span><span class="normal"> registration_id</span><span class="symbol">;</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"notify"</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">send_property_change</span><span class="symbol">),</span><span class="normal"> connection</span><span class="symbol">);</span>
<span class="normal">  registration_id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GDBusConnection.html#g-dbus-connection-register-object">g_dbus_connection_register_object</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                                                       </span><span class="string">"/org/myorg/MyObject"</span><span class="symbol">,</span>
<span class="normal">                                                       introspection_data</span><span class="symbol">-&gt;</span><span class="normal">interfaces</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">],</span>
<span class="normal">                                                       </span><span class="symbol">&amp;</span><span class="normal">interface_vtable</span><span class="symbol">,</span>
<span class="normal">                                                       myobj</span><span class="symbol">,</span>
<span class="normal">                                                       <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal">  </span><span class="comment">/* user_data_free_func */</span>
<span class="normal">                                                       <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span><span class="normal"> </span><span class="comment">/* GError** */</span>
<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">registration_id </span><span class="symbol">&gt;</span><span class="normal"> </span><span class="number">0</span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">on_name_acquired</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">                  </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">     </span><span class="symbol">*</span><span class="normal">name</span><span class="symbol">,</span>
<span class="normal">                  </span><span class="usertype">gpointer</span><span class="normal">         user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">on_name_lost</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GDBusConnection</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">connection</span><span class="symbol">,</span>
<span class="normal">              </span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal">     </span><span class="symbol">*</span><span class="normal">name</span><span class="symbol">,</span>
<span class="normal">              </span><span class="usertype">gpointer</span><span class="normal">         user_data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="function">exit</span><span class="normal"> </span><span class="symbol">(</span><span class="number">1</span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="type">int</span>
<span class="function">main</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> argc</span><span class="symbol">,</span><span class="normal"> </span><span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">argv</span><span class="symbol">[])</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">guint</span><span class="normal"> owner_id</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">GMainLoop</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">loop</span><span class="symbol">;</span>
<span class="normal">  </span><span class="usertype">MyObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">myobj</span><span class="symbol">;</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Type-Information.html#g-type-init">g_type_init</a></span><span class="normal"> </span><span class="symbol">();</span>

<span class="normal">  </span><span class="comment">/* We are lazy here - we don't want to manually provide</span>
<span class="comment">   * the introspection data structures - so we just build</span>
<span class="comment">   * them from XML.</span>
<span class="comment">   */</span>
<span class="normal">  introspection_data </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="gio-D-Bus-Introspection-Data.html#g-dbus-node-info-new-for-xml">g_dbus_node_info_new_for_xml</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">introspection_xml</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">introspection_data </span><span class="symbol">!=</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="normal">  myobj </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-new">g_object_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">my_object_get_type</span><span class="normal"> </span><span class="symbol">(),</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="normal">  owner_id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="gio-Owning-Bus-Names.html#g-bus-own-name">g_bus_own_name</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="GDBusConnection.html#G-BUS-TYPE-SESSION:CAPS">G_BUS_TYPE_SESSION</a></span><span class="symbol">,</span>
<span class="normal">                             </span><span class="string">"org.myorg.MyObject"</span><span class="symbol">,</span>
<span class="normal">                             <a href="gio-Owning-Bus-Names.html#G-BUS-NAME-OWNER-FLAGS-NONE:CAPS">G_BUS_NAME_OWNER_FLAGS_NONE</a></span><span class="symbol">,</span>
<span class="normal">                             on_bus_acquired</span><span class="symbol">,</span>
<span class="normal">                             on_name_acquired</span><span class="symbol">,</span>
<span class="normal">                             on_name_lost</span><span class="symbol">,</span>
<span class="normal">                             myobj</span><span class="symbol">,</span>
<span class="normal">                             <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="normal">  loop </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-main-loop-new">g_main_loop_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-main-loop-run">g_main_loop_run</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">loop</span><span class="symbol">);</span>

<span class="normal">  </span><span class="function"><a href="gio-Owning-Bus-Names.html#g-bus-unown-name">g_bus_unown_name</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">owner_id</span><span class="symbol">);</span>

<span class="normal">  </span><span class="function"><a href="gio-D-Bus-Introspection-Data.html#g-dbus-node-info-unref">g_dbus_node_info_unref</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">introspection_data</span><span class="symbol">);</span>

<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">myobj</span><span class="symbol">);</span>

<span class="normal">  </span><span class="keyword">return</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="cbracket">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break">
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.17</div>
</body>
</html>